ohibc logo
OHI British Columbia | OHI Science | Citation policy

knitr::opts_chunk$set(fig.width = 6, fig.height = 4, fig.path = 'Figs/',
                      echo = TRUE, message = FALSE, warning = FALSE)

dir_git <- '~/github/ohibc'
source(file.path(dir_git, 'src/R/common.R'))  ### an OHIBC specific version of common.R
dir_rgn <- file.path(dir_git, 'prep/regions')  ### github: general buffer region shapefiles
dir_anx <- file.path(dir_M, 'git-annex/bcprep')


### goal specific folders and info
goal      <- 'fis'
scenario  <- 'v2017'
dir_goal  <- file.path(dir_git, 'prep', goal, scenario)
dir_spatial  <- file.path(dir_git, 'prep/_spatial')

### provenance tracking
library(provRmd); prov_setup()

### support scripts
source(file.path(dir_git, 'src/R/rast_tools.R')) 
  ### raster plotting and analyzing scripts

### set up proj4string options: BC Albers and WGS84
p4s_wgs84 <- '+proj=longlat +datum=WGS84 +no_defs +ellps=WGS84 +towgs84=0,0,0'
p4s_bcalb <- '+proj=aea +lat_1=50 +lat_2=58.5 +lat_0=45 +lon_0=-126 +x_0=1000000 +y_0=0 +datum=NAD83 +units=m +no_defs +ellps=GRS80 +towgs84=0,0,0'

1 Summary

This script takes the output from functions.R FIS model and plots individual stock scores by year and relative contribution to score.

1.1 Stock scores and overall scores by region

## plotting fishery catch weighting by region
stock_plot_df <- read_csv(file.path(dir_goal, 'summary/fis_from_functions.csv')) %>%
  filter(!is.na(score)) %>%
  group_by(region_id, year) %>%
  mutate(total_catch = sum(rgn_catch),
         rgn_catch_pct = rgn_catch / total_catch,
         total_score = sum(score * rgn_catch) / total_catch) %>%
  ungroup() %>%
  left_join(get_rgn_names(), by = c('region_id' = 'rgn_id')) %>%
  filter(rgn_catch > 0)
for(rgn in 1:8) {
  # rgn <- 1
  rgn_plot_df <- stock_plot_df %>%
    filter(region_id == rgn)
  status_plot <- ggplot(rgn_plot_df, aes(x = year, y = score)) +
    ggtheme_plot() +
    geom_line(aes(group = stock_id, color = stock_id,
                  size = rgn_catch_pct),
              lineend = 'round', alpha = .5) +
    # scale_size_continuous(guide = FALSE) +
    geom_point(data = rgn_plot_df %>%
                 filter(!str_detect(basis, 'F/Fmsy')),
               color = 'grey30', size = 1) +
    geom_line(data = rgn_plot_df %>%
                select(year, total_score) %>%
                distinct(),
              aes(x = year, y = total_score),
              size = 1.5, color = 'grey30')  +
    labs(title = first(rgn_plot_df$rgn_name),
         color = 'Stock ID',
         y     = 'Stock Score') +
    guides(colour = guide_legend(override.aes = list(size = 3)),
           size = 'none')
  print(status_plot)
}

1.2 Catch by stock and region

for(rgn in 1:8) {
  rgn_plot_df <- stock_plot_df %>%
    filter(region_id == rgn) 
  status_plot <- ggplot(rgn_plot_df, aes(x = year, y = rgn_catch)) +
    ggtheme_plot() +
    geom_line(aes(group = stock_id, color = stock_id),
              alpha = .5, size = 2) +
    labs(title = first(rgn_plot_df$rgn_name),
         color = 'Stock ID',
         y     = 'Stock reported catch') +
    guides(colour = guide_legend(override.aes = list(size = 3)),
           size = 'none')
  print(status_plot)
}


prov_wrapup(commit_outputs = FALSE)

2 Provenance

  • Run ID: 3 (9874952); run tag: “standard run”
  • Run elapsed time: 13.418 seconds; run memory usage: 1832 MB
  • System info:
    • System: Linux, Release: 4.4.0-57-generic. Machine: x86_64. User: ohara.
    • R version: R version 3.4.1 (2017-06-30), Platform: x86_64-pc-linux-gnu, Running under: Ubuntu 14.04.5 LTS.
    • Attached base packages: stats, graphics, grDevices, utils, datasets, methods, base
    • Other attached packages: provRmd_0.1.1, stringr_1.2.0, RColorBrewer_1.1-2, dplyr_0.5.0, purrr_0.2.2, readr_1.1.0, tidyr_0.6.2, tibble_1.3.3, ggplot2_2.2.1.9000, tidyverse_1.1.1
%3 5 rast_tools.R 6 fis_from_functions.csv 2 3_plot_fis_scores.Rmd#assemble_dataframe 6->2 used 1 3_plot_fis_scores.Rmd 4 3_plot_fis_scores.Rmd#setup 1->4 wasExecutedBy 1->2 wasExecutedBy 3 3_plot_fis_scores.Rmd#provenance 1->3 wasExecutedBy 4->5 wasExecutedBy